import { defineStore } from 'pinia'
import { ref } from 'vue'
import { classAll } from '@/api/course'
import { useRouter } from 'vue-router'
import { stuAll } from '@/api/course'

export const useClasStore = defineStore(
  'use-class',
  () => {
    const router = useRouter()
    //班级列表
    const classList = ref([])
    classAll().then((res) => {
      // console.log(res.data)
      classList.value = res.data
      // console.log(classList.value)
      console.log(classList)
    })

    // 删除数据
    const deleteData = (id) => {
      console.log(id)
      classList.value = classList.value.filter((item) => item.classId !== id)
    }

    // 所有学生
    const stuList = ref([])
    // 学生信息管理
    const stuManage = (id) => {
      let Id = ref('')
      Id.value = id
      stuAll(Id).then((res) => {
        stuList.value = res.data
        console.log(res.data)
      })
      router.push('/classStuInfo')
    }

    return {
      classList,
      deleteData,
      stuManage,
      stuList
    }
  },
  {
    persist: true
  }
)
